package com.woniuxy.controller.goodsGeneralAndSmallAndBrand;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.annotation.Validate;
import com.woniuxy.demo.Result;
import com.woniuxy.entity.GoodsGeneral;
import com.woniuxy.param.goodsGeneralAndSmallAndBrand.AddGoodsGeneralParam;
import com.woniuxy.param.goodsGeneralAndSmallAndBrand.DeleteGeneralParam;
import com.woniuxy.param.goodsGeneralAndSmallAndBrand.ListGoodsGeneralParam;
import com.woniuxy.param.goodsGeneralAndSmallAndBrand.UpdateGoodsGeneralParam;
import com.woniuxy.service.GoodsGeneralService;
import com.woniuxy.util.ValidatedUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 范腾龙
 * @version 1.0
 * 关于商品大类信息管理的接口
 * @since 2021-1-1
 */
@RestController
@Api(tags = "关于商品大类信息管理的接口")

@RequestMapping("/goods-general")
public class GoodsGeneralController {

    @Autowired
    private GoodsGeneralService goodsGeneralService;


    /**
     * 新增大类信息后端接口
     *
     * @param bindingResult
     * @param addGoodsGeneralParam
     * @return
     */
    @PostMapping("/addGeneralInfo")
    @ApiOperation("新增大类信息")
    public Result addGeneralInfo(@Validated @RequestBody  AddGoodsGeneralParam addGoodsGeneralParam,BindingResult bindingResult) {
        //参数验证
        ValidatedUtil.ValidatedException(bindingResult);
        return Result.newInstance().setCode(200).setMsg("新增成功")
                .setData(goodsGeneralService.saveGeneralInfo(addGoodsGeneralParam));
    }

    /**
     * 分页查询大类信息后端接口
     *
     * @param bindingResult
     * @param listGoodsGeneralParam
     * @return
     */
    @PostMapping("/pageGeneralInfo")
    @ApiOperation("分页查询大类信息")
    public Result pageGeneralInfo( @Validated @RequestBody ListGoodsGeneralParam listGoodsGeneralParam,BindingResult bindingResult) {

        return Result.newInstance().setCode(200).setMsg("查询成功")
                .setData(goodsGeneralService.pageFind(listGoodsGeneralParam));
    }

    /**
     * 修改大类信息后端接口
     *
     * @param bindingResult
     * @param updateGoodsGeneralParam
     * @return
     */
    @PostMapping("/updateGeneralInfo")
    @ApiOperation("修改大类信息")
    public Result updateGeneralInfo(@Validated @RequestBody  UpdateGoodsGeneralParam updateGoodsGeneralParam,BindingResult bindingResult) {
        //参数验证
        ValidatedUtil.ValidatedException(bindingResult);
        return Result.newInstance().setCode(200).setMsg("修改成功")
                .setData(goodsGeneralService.updateGeneralInfo(updateGoodsGeneralParam));
    }


    /**
     * 批量删除大类信息后端接口
     *
     * @param bindingResult
     * @param deleteGeneralParam
     * @return
     */
    @PostMapping("/removeGeneralInfo")
    @ApiOperation("批量删除大类信息")
    public Result removeGeneralInfo(@Validated @RequestBody  DeleteGeneralParam deleteGeneralParam,BindingResult bindingResult) {
        //参数验证
        ValidatedUtil.ValidatedException(bindingResult);
        if (goodsGeneralService.deleteGoodsGeneral(deleteGeneralParam))
            return Result.newInstance().setCode(200).setMsg("删除成功");
        return Result.newInstance().setCode(500).setMsg("删除失败");
    }


    /**
     * 根据大类id查询大类信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getGeneralById/{id}")
    @ApiOperation("单个查询大类信息")
    public Result getGeneralById(@PathVariable("id") Integer id) {
        return Result.newInstance().setCode(200).setMsg("查询成功")
                .setData(goodsGeneralService.getById(id));
    }

    /**
     * 查询所有大类信息
     * @return
     */
    @GetMapping("/listAllGeneral")
    @ApiOperation("查询所有大类信息")
    public Result listAllGeneral() {
        return Result.newInstance().setCode(200).setMsg("查询成功")
                .setData(goodsGeneralService.list());
    }

    /**
     * 查询未删除大类信息
     * @return
     */
    @GetMapping("/listGeneral")
    @ApiOperation("查询未删除大类信息")
    public Result listGeneral() {
        return Result.newInstance().setCode(200).setMsg("查询成功")

                .setData(goodsGeneralService.list(new QueryWrapper<GoodsGeneral>().in("goods_general_status",0)));
    }

}

